<template>
    <div class="mod-prod-prodTag">
        <search-form :showArea="true" :showStatus="false" @search="customSearch"></search-form>
        <avue-crud ref="crud" :data="dataList" :option="tableOption" :page="page" :search="query"
                   :table-loading="dataListLoading"
                   @search-change="searchChange" @on-load="" @refresh-change="refreshChange">
            <template slot="menu" slot-scope="scope">
                <el-button icon="el-icon-edit" size="small" type="primary"
                           @click="handleAudit(scope.row)">评审确认
                </el-button>
            </template>
            <template slot-scope="scope"
                      slot="biz2">
                <el-tag v-if="scope.row.biz2 === ''"
                        size="small"
                        type="danger">处理中</el-tag>
                <el-tag v-if="scope.row.biz2 === 'Y'"
                        size="small"
                        type="success">已确认</el-tag>
                <el-tag v-if="scope.row.biz2 === 'N'"
                        size="small"
                        type="danger">已驳回</el-tag>
            </template>
        </avue-crud>
        <el-dialog :close-on-click-modal="false" :visible.sync="editVisible" custom-class="my-dialog" height="90vh"
                   title="数据填报详情" top="5vh" width="95%">
            <target-edit ref="editRef" :editFormData="editFormData" controlType="admin"
                         @success="success"></target-edit>
        </el-dialog>
    </div>
</template>

<script>
import {
	tableOption
} from '@/crud/admin-audit/admin-audit'
import TargetEdit from '@/template/target-edit/index.vue'
import SearchForm from '@/components/search-form/index.vue'

export default {
	data () {
		return {
			params: {
				evalYear: wfy.format('yyyy', new Date()),
				evalStatus: 'F'
			},
			editFormData: {},
			editVisible: false,
			dataList: [],
			page: {
				total: 0, // 总页数
				currentPage: 1, // 当前页数
				pageSize: 10 // 每页显示多少条
			},
			query: {
				evalYear: wfy.format('yyyy', new Date())
			},
			dataListLoading: false,
			tableOption: tableOption,
			permission: {
				delBtn: this.isAuth('prod:prodTag:delete')
			},
			addOrUpdateVisible: false
		}
	},
	components: {
		SearchForm,
		TargetEdit

	},
	created () {
	},
	activated () {
		if (!wfy.empty(wfy.getPara('evalYear'))) {
			this.getDataList(1, {
				//reginId: wfy.getPara("reginId"),
				evalYear: wfy.getPara('evalYear'),
				evalStatus: 'F',
			})
		} else {
			this.getDataList(1, this.params)
		}
	},
	mounted () {
		this.init()
	},
	methods: {
		init () {
			this.yearsList = []
			for (let i = 2024; i < 2060; i++) {
				this.yearsList.push({
					value: i,
					label: i
				})
			}
			let areaList = this.$store.state.user.area.area
			this.tableOption.column.forEach((item) => {
				if (item.prop === 'evalYear') {
					item.dicData = this.yearsList
				}
				if (item.prop === 'reginId') {
					areaList.forEach((area) => {
						item.dicData.push({
							value: area.code,
							label: area.name
						})
					})
					console.log('🚀 ~ item.dicData', item.dicData)
				}
			})
			this.getDataList(1, {
				//reginId: wfy.getPara("reginId"),
				evalYear: wfy.format('yyyy', new Date()),
				evalStatus: 'F',
			})
		},
		customSearch (params) {
			this.getDataList(1, {
				evalYear: params.evalYear,
				evalStatus: 'F',
				reginId: params.regionId,
				provinceId: params.provinceId,
				cityId: params.cityId
			})
		},
		getDataList (page, params, done) {
			this.dataListLoading = true
			this.dataList = []
			this.params = params
			this.$http({
				url: this.$http.adornUrl('/eval/getEvalInfoList'),
				method: 'post',
				data: this.$http.adornData(
					Object.assign(
						{
							current: page == null ? this.page.currentPage : page.currentPage,
							size: page == null ? this.page.pageSize : page.pageSize,
							evalStatus: 'F'
						},
						params
					)
				)
			}).then(({
				data
			}) => {
				console.log('🚀 ~ data', data)
				this.dataList = data
				// this.totalResult.forEach((item) => {
				//     this.dataList.push(item.evaluationMain)
				// })
				this.page.total = data.length
				this.dataListLoading = false
				if (done) {
					done()
				}
			})
		},
		// 新增 / 修改
		handleAudit (row) {
			console.log('🚀 ~ row', row)
			this.$http({
				url: this.$http.adornUrl('/eval/getNowEvalInfo'),
				method: 'post',
				data: this.$http.adornData({
					'evalMainId': row.evalMainId,
					'evalYear': row.evalYear,
					'reginId': row.reginId
				})
			}).then(({
				data
			}) => {
				console.log('🚀 ~ data', data)
				let orReadyItem = {
					affixList: data[0].affixList,
					anIndexEvaluationMain: data[0].evaluationMain,
					currentEvalDtl: data[0].currentEvalDtl,
					currentIndexInfo: data[0].currentIndexInfo,
					scoreList: data[0].scoreList
				}
				this.initSuccess(orReadyItem)
			})
		},
		/**
		 * 刷新回调
		 */
		initSuccess (data) {
			console.log('🚀 ~ data', data)
			// sessionStorage.expertInitFormData = JSON.stringify(wfy.deepCopy(data));
			// this.$router.push({
			//     path: 'expert-detail',
			//     query: { id : data.anIndexEvaluationMain.evalMainId }
			// })
			this.editFormData = data
			this.editVisible = false
			this.$nextTick(() => {
				this.editVisible = true
				this.$refs.editRef.initData()
			})
		},
		/**
		 * 刷新回调
		 */
		refreshChange () {
			this.getDataList(this.page)
		},
		searchChange (params, done) {
			if (wfy.empty(params)) {
				this.$message.warning('查询条件不能为空')
				done()
				return
			}

			/*** if(wfy.empty(params.reginId)){
                this.$message.warning('请选择区县后进行查询');
                done()
                return;
            }**/
			if (wfy.empty(params.evalYear)) {
				this.$message.warning('填报年度不能为空')
				done()
				return
			}
			this.getDataList(this.page, params, done)
		},
		success (message) {
			console.info(message)
			this.editVisible = false
			this.$alert('确认完成！', '友情提醒', {
				callback: () => {
					// this.removeTabHandle(this.mainTabsActiveName)
					// this.$router.push({
					//     path: 'expert-review',
					//     query: {  evalYear : message.evalYear, evalStatus : message.evalStatus }
					// })
					this.getDataList(1, {
						evalYear: message.evalYear,
						evalStatus: 'F',
					})
				}
			})
		}
	}
}
</script>

<style scoped>

.mod-prod-prodTag >>> .my-dialog {
    height: 90vh !important;
    overflow-y: scroll;
}

</style>
